<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>附件管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <!--标准mui.css-->
    <link rel="stylesheet" href="../mui/hello-mui/css/mui.min.css">
    <!-- 异步上传 -->
    <script src="../dece/js/app.js" type="text/javascript"></script>
    <script src="../dece/js/vue.js" type="text/javascript"></script>
    <script src="../dece/js/axios.min.js" type="text/javascript"></script>

    <style type="text/css">
        .de_header {
            height: 45px;
            text-align: center;
        }
        .de_header span {
            line-height: 45px;
            font-size: 18px;
        }
        .de_input {
            padding: 1rem;
        }
        .pname {
            display: flex;
            flex-flow: row nowrap;
            justify-content: space-between;
        }
    </style>
</head>
<body>
    <div id="app">
        <header class="mui-bar mui-bar-transparent">
            <a class="mui-icon mui-action-back mui-icon-left-nav mui-pull-left"></a>
            <h1 class="mui-title">附件管理</h1>
            <a class="mui-icon mui-icon-bars mui-pull-right" href="#menu_right"></a>
        </header>
        <div class="mui-content" style="padding-top: 2rem;">
            <div class="mui-card" v-for="row in images">
                <div class="mui-card-header mui-card-media" :style="{'background-image': 'url('+api_host+row.url+')'}" style="height:40vw;"></div>
                <div class="mui-card-content">
                    <div class="mui-card-content-inner">
                        <p class="pname"><span>{{row.name}}</span><span>{{row.addtime}}</span></p>
                    </div>
                </div>
            </div>
        </div>
        <div style="padding: 0px 10px;">
            <button type="button" class="mui-btn mui-btn-royal" style="float: right;">更多</button>
        </div>
        <!-- 弹出层 start -->
        <div id="menu_right" class="mui-popover mui-popover-action mui-popover-bottom">
            <ul class="mui-table-view">
                <li class="mui-table-view-cell">
                    <a href="#uploads">上传附件</a>
                </li>
                <li class="mui-table-view-cell">
                    <a href="#">其他设置</a>
                </li>
            </ul>
            <ul class="mui-table-view">
                <li class="mui-table-view-cell">
                    <a href="#menu_right"><b>取消</b></a>
                </li>
            </ul>
        </div>
        <div id="uploads" class="mui-popover mui-popover-action mui-popover-bottom">
            <div class="mui-card">
                <form class="mui-input-group">
                    <div class="de_header">
                        <span>附件上传</span>
                    </div>
                    <div class="mui-input-row">
                        <label>分类选择</label>
                        <select v-model="file_type">
                            <option v-for="row in file_type_option" :value="row.id">
                                {{row.name}}
                            </option>
                        </select>
                    </div>
                    <div class="de_input">
                        <input type="file" multiple="multiple">
                    </div>
                    <div class="mui-button-row">
                        <a @click="upload" type="button" class="mui-btn mui-btn-primary">确认</a>&nbsp;&nbsp;
                        <a type="button" class="mui-btn mui-btn-danger" href="#uploads">取消</a>
                    </div>
                </form>    
            </div>
        </div>
        <!-- 弹出层 end -->
    </div>
    <script src="../mui/hello-mui/js/mui.min.js"></script>
    <script type="text/javascript" charset="utf-8">
        mui.init({
            swipeBack:true //启用右滑关闭功能
        });
        new Vue({
            el: '#app',
            data: {
                api_host: window.de.api_host,
                tid: '',
                images: [],
                file_type: '',
                file_type_option: [],
            },
            created: function (){
                var the = this;
                // 分类id
                this.tid = de.get('tid');
                // 加载图片
                this.index();
                // 分类加载
                axios.get(de.file_type).then(function (data){
                    var dd = data.data;
                    if (dd.code == 200) {
                        the.file_type_option = dd.data; 
                    } else {
                        console.log(dd.info);
                    }
                }).catch(function (error) {
                    console.log(error);
                });
            },
            methods: {
                // 页面显示
                index: function (){
                    var the = this;
                    axios.get(de.file_index + '/tid/' + this.tid).then(function (data){
                        var dd = data.data;
                        if (dd.code == 200) {
                            the.images = dd.data; 
                        } else {
                            console.log(dd.info);
                        }
                    }).catch(function (error) {
                        console.log(error);
                    });
                },
                // 上传文件
                upload: function (){
                    var forms = de.upload('input', 'upload_img[]');
                    // 追加元素
                    forms.formData.append('tid', this.file_type);
                    // 提交数据
                    axios.post(de.file_upload, forms.formData).then(function (data){
                        var dd = data.data;
                        if (dd.code == 200) {
                            mui.alert(dd.info, '成功', '确定'); 
                        } else {
                            mui.alert(dd.info, '失败', '确定'); 
                        }
                    }).catch(function (error) {
                        console.log(error);
                    });
                },
            }
        });
    </script>
</body>
</html>